import { fromJS } from 'immutable'
import * as types from './action-types'

const defaultState = fromJS({
  searchValue: {
    userName: '',
    role: ''
  },
  actionKey: 'save',
  loading: false,
  formData: {}
})

export default (state = defaultState, action) => {
  switch (action.type) {
    case types['CHANGE_SEARCH_USERNAME']:
      return state.setIn(['searchValue', 'userName'], action.value)
    case types['CHANGE_SEARCH_ROLE']:
      return state.setIn(['searchValue', 'role'], action.value)
    case types['CHANGE_ACTIONKEY']:
      return state.set('actionKey', action.key)
    case types['CHANGE_LOADING']:
      return state.set('loading', action.bol)
    case types['CHANGE_FORMDATA']:
      return state.set('formData', action.data)
    default:
      return state
  }
}
